package com.shop.dao;

import com.shop.dto.AddressQueryDto;
import com.shop.entity.AddressEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author wzby
 * @Date: 2022/12/8 15:25
 */
@Mapper
public interface AddressMapper {

    @Insert("insert shop_address (name,phone,province, city,county, zipCode,detail, memberId,isDefault,lastUpdateTime)" +
            " values (#{name},#{phone},#{province},#{ city},#{county},#{zipCode},#{detail},#{memberId},#{isDefault},#{lastUpdateTime})")
    int insert(AddressEntity addressEntity);

    @Select("<script> select *  from shop_address where 1 = 1" +
            " <if test ='memberId != null' >" +
            " and  memberId = #{memberId} " +
            " </if> " +
            " <if test ='id != null' >" +
            " and id = #{id} " +
            " </if> " +
            "</script>")
    List<AddressEntity> select(AddressQueryDto addressQueryDto);


    @Insert("update shop_address set isDefault = 0" +
            " where memberId = #{memberId}")
    int updateDefaultFlag(Integer memberId);
}
